var express = require("express");
var router = express.Router();
var { ParseToken } = require("../utils/token");
/* GET home page. */
router.get("/", async function (req, res, next) {
    //获取用户传递过来的token
    var token = req.headers['x-token']
    // 解析token 验证用户
    let user = ParseToken(token)
    if(user){
      let userinfo = await Select(user)
      let uplevel = userinfo.level  
      const {_id,username,password,level} = req.body
      if(uplevel<4){
        let result = await updateUserById(_id,{username,password,level})
        res.send({code:0,msg:"修改成功",result:result })
      }else{
        res.send({code:-1,msg:"您的权限不够，请先提升权限"})
      }
    }else{
      res.send({code:-1,msg:"token失效"})
    }
});

module.exports = router;